package com.atomic.test.example.repository;

import com.atomic.test.example.entity.Board;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author dreamyao
 * @title
 * @date 2021/11/10 7:16 下午
 * @since 1.0.0
 */
public interface BoardRepository extends JpaRepository<Board,Integer> {

    Board getBoardByBoardName(String boardName);

    void deleteBoardById(Integer id);

    Board findBoardById(Integer id);

    /**
     * 根据板块Id更新话题数
     * @param id
     * @param topicNum
     */
    @Modifying
    @Transactional
    @Query("update Board set topicNum=:topicNum where id=:id")
    Integer updateTopicNumByBoardId(@Param("id") Integer id, @Param("topicNum") Integer topicNum);
}
